function features = gmrf(gray_img)
    % 将图像转换为双精度类型
    gray_img = double(gray_img);
    
    % 获取图像的尺寸
    [rows, cols] = size(gray_img);
    
    % 初始化 GMRF 参数
    mu = mean(gray_img(:)); % 均值
    sigma2 = var(gray_img(:)); % 方差
    beta = zeros(1, 4); % 四个邻域方向的参数
    
    % 定义邻域偏移
    offsets = [0 1; 1 0; 1 1; 1 -1];
    
    % 计算 GMRF 参数
    for k = 1:4
        offset = offsets(k, :);
        shifted_img = circshift(gray_img, offset);
        beta(k) = sum(sum((gray_img - mu) .* (shifted_img - mu))) / (rows * cols * sigma2);
    end
    
    % 将均值、方差和 GMRF 参数作为特征返回
    features = [mu, sigma2, beta];
end